! ----------------------------------------------------------------------
!
!    Modem Script for WX310K by Kyocera
!
!    05/10/2005
!
!    Copyright 2005 Kyocera Corporation All rights reserved.
!
! ----------------------------------------------------------------------

@ORIGINATE
@ANSWER

!
!  Initial setup
!

serreset 230400, 0, 8, 1
hsreset 0 0 0 0 0 0
settries 0
flush

!
!  Get the modem's attention
!

matchclr
matchstr 1 3 "OK\13\10"
write "AT\13"
matchread 50

!
!  Setup the modem
!

@LABEL 3
matchclr
matchstr 1 4  "OK\13\10"
matchstr 2 101 "ERROR\13\10"
write "AT&FE0X4V1Q0&D2&C1S0=0\13"
matchread 50
inctries
iftries 3 101

!
!  Reset the Modem on setup failure
!

DTRClear
pause 5
DTRSet
flush
jump 3
!
@LABEL 4
matchclr
matchstr 1 13  "OK\13\10"
matchstr 2 101 "ERROR\13\10"
write "ATS7=60+IFC=2\13"
matchread 50
!
@LABEL 5
matchclr
matchstr 1 13  "OK\13\10"
matchstr 2 101 "ERROR\13\10"
write "ATS0=0\13"
matchread 50

!
!  Originating a call.
!

@LABEL 13
ifANSWER 32

!
!  Dial
!

@LABEL 19

!
! Display the full dialstring contained in Varstring 1
!

note "Dialing ^1" 3

!
! Varstrings 7, 8 and 9, contain dialstring fragments
!    Long phone numbers may need to be split into smaller groups
!    for the modem to use
!
! Varstring 8 == blank (dialstring in varstring 7)
! Varstring 9 == blank (dialstring in varstrings 7 & 8)
! Otherwise (dialstring in varstrings 7, 8 & 9)
!

ifstr 8 21 " "
ifstr 9 20 " "

!
!  Write dialstring in varstrings 7, 8 & 9
!

write "ATD^7^8^9\13"
jump 32

!
!  Write dialstring in varstrings 7 & 8
!

@LABEL 20
write "ATD^7^8\13"
jump 32

!
!  Write dialstring in varstring 7
!

@LABEL 21
write "ATD^7\13"

!
!  Parse the modem's response.
!

@LABEL 32
matchclr
matchstr  1 33  "CONNECT "
matchstr  2 52  "CONNECT\13"
matchstr  3 81  "RING\13\10"
matchstr  4 102 "NO DIALTONE\13\10"
matchstr  5 104 "BUSY\13\10"
matchstr  6 105 "NO CARRIER"
matchstr  7 105 "ERROR\13\10"
matchstr  8 107 "DELAYED\13\10"
matchstr  9 110 "NO ANSWER\13\10"

matchread 600
ifANSWER 32
jump 101

!
!  Parse the speed of connect result code
!

@LABEL 33
matchclr
matchstr  1 41 "1200"
matchstr  2 42 "2400"
matchstr  3 43 "4800"
matchstr  4 44 "7200"
matchstr  5 45 "9600"
matchstr  6 46 "12000"
matchstr  7 47 "14400"
matchstr  8 48 "19200"
matchstr  9 49 "38400"
matchstr  10 50 "57600"
matchstr  11 51 "115200"
matchstr  12 52 "230400"
matchread 30
jump 59

!
! Set Connection rates
!

@LABEL 41
note "Communicating at 1200 bps." 2
CommunicatingAt 1200
jump 70
!
@LABEL 42
note "Communicating at 2400bps." 2
CommunicatingAt 2400
jump 70
!
@LABEL 43
note "Communicating at 4800bps." 2
CommunicatingAt 4800
jump 70
!
@LABEL 44
note "Communicating at 7200bps." 2
CommunicatingAt 7200
jump 70
!
@LABEL 45
note "Communicating at 9600bps." 2
CommunicatingAt 9600
jump 70
!
@LABEL 46
note "Communicating at 12000 bps." 2
CommunicatingAt 12000
jump 70
!
@LABEL 47
note "Communicating at 14400 bps." 2
CommunicatingAt 14400
jump 70
!
@LABEL 48
note "Communicating at 19200 bps." 2
CommunicatingAt 19200
jump 70
!
@LABEL 49
note "Communicating at 38400 bps." 2
CommunicatingAt 38400
jump 70
!
@LABEL 50
note "Communicating at 57600 bps." 2
CommunicatingAt 57600
jump 70
!
@LABEL 51
note "Communicating at 115200 bps." 2
CommunicatingAt 115200
jump 70
!
@LABEL 52
note "Communicating at 230400 bps." 2
CommunicatingAt 230400
jump 70
!
@LABEL 59
note "Communicating at unkown rate." 2
jump 70
!
@LABEL 70

!
! Turn on CTS handshaking.
!

HSReset 0 1 0 0 0 0

ifANSWER 71
pause 30
!
@LABEL 71
exit 0

!
!  Answer calls
!
!  A RING result from the modem when in ANSWER mode claims the
!  serial port and answers the phone
!

@LABEL 81
ifORIGINATE 32
userhook 1
note "Answering phone..." 2
write "ATA\13"
jump 32

!
!  Hang up and reset modem
!

@HANGUP
@LABEL 90
settries 0
HSReset 0 0 0 0 0 0
!
@LABEL 92

!
!  Escape from data to command mode
!

matchclr
matchstr 1 94 "OK\13\10"
write "+++"
matchread 20
!
@LABEL 93
matchclr
matchstr 1 95 "NO CARRIER\13\10"
matchstr 2 95 "OK\13\10"
matchstr 3 95 "ERROR\13\10"
matchstr 4 95 "0\13\10"
write "ATH\13"
matchread 50

! 
!  Try to get control of the modem by toggling DTR
!

DTRClear
pause 5
DTRSet
flush

!
!  Try the hangup sequence three times otherwise declare and error
!

inctries
iftries 3 101
jump 92

!
!  Pause between data and command mode
!

@LABEL 94
pause 50
jump 93

!
!  Recall the factory settings
!

@LABEL 95
pause 15
matchclr
matchstr 1 96 "OK\13\10"
write "AT&FE0X4V1Q0&D2&C1S0=0\13"
matchread 50
jump 101
!
@LABEL 96
matchclr
matchstr 1 97 "OK\13\10"
write "ATS7=60+IFC=2\13"
matchread 50
jump 101
!
@LABEL 97
matchclr
matchstr 1 99 "OK\13\10"
write "ATS0=0\13"
matchread 50
jump 101
!
@LABEL 99
exit 0

!
!  Error messages
!

!
!  Modem Not Responding
!

@LABEL 101
write "AT&F\13"
pause 10
exit -6019

!
! No Dial Tone
!

@LABEL 102
exit -6020

!
! Busy
!

@LABEL 104
exit -6022

!
!  No Carrier or Error
!

@LABEL 105
matchstr 1 106 "OK\13\10"
write "AT&F\13"
matchread 50
!
@LABEL 106
exit -6021

!
!  Delayed
!

@LABEL 107
matchstr 1 108 "OK\13\10"
write "AT&F\13"
matchread 50
!
@LABEL 108
exit -6022

!
! No Answer
!

@LABEL 110
exit -6023

